#include "Vector.h"
#include <iostream>
using std::cout;
using std::endl;
using std::max;
using std::min;
//Vector

template<typename T>
Vector<T>::
Vector():start(nullptr),finish(nullptr), end_of_storage(nullptr) 
{
    
}



template<typename T>
Vector<T>::
~Vector(){
    while(finish != start){
        _alloc.destroy(--finish);
    }
    _alloc.deallocate(start,capacity());
}

template<typename T>
void Vector<T>::reallocate(){
    size_t new_capacity = (capacity() > 0)?(2 * size()):1;
    T *temp = _alloc.allocate(new_capacity);
    copy(start, finish, temp);
    size_t cur_size = size();
    while(finish != start){
        _alloc.destroy(--finish);
    }
    _alloc.deallocate(start,capacity());
    start = temp;
    finish = start + cur_size;
    end_of_storage = start + new_capacity;
}

template<typename T>
size_t Vector<T>::size() const{
    return finish - start;
}


template<typename T>
size_t Vector<T>::capacity()const{
    return end_of_storage - start;
}

template<typename T>
void Vector<T>::push_back(const T &ch){
    if(finish == end_of_storage){
        reallocate();
    }
    _alloc.construct(finish++, ch);
} 

template<typename T>
void Vector<T>::pop_back(){
    _alloc.destroy(--finish);
} 


template<typename T>
T &Vector<T>::operator[](const size_t index){
    return *(start + index);
}
template<typename T>
const T &Vector<T>::operator[](size_t index) const{
    return *(start + index);
}




